//
//  BankListViewController.m
//  YaDiuDiu
//
//  Created by 陈刚 on 2017/10/19.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "BankListViewController.h"

@interface BankListViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) NSMutableArray *bankArray;

@end

@implementation BankListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showNav:@"银行列表"];
    
    self.bankTable.tableFooterView = [[UIView alloc]init];
    
    [self loadData];
    
    // Do any additional setup after loading the view from its nib.
}

- (void)loadData{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:token forKey:@"verifyToken"];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Usercenter/bank",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"银行列表res:%@",responseObject);
        self.bankArray = [responseObject objectForKey:@"content"];
        [self.bankTable reloadData];
        
        [SVProgressHUD dismiss];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.bankArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *Identitfer = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identitfer];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identitfer];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary *itemDic = [self.bankArray objectAtIndex:indexPath.row];
    [cell.textLabel setText:[itemDic objectForKey:@"bankname"]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *itemDic = [self.bankArray objectAtIndex:indexPath.row];
    [self.delegate selectBankAction:itemDic];
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSMutableArray *)bankArray{
    if (!_bankArray) {
        _bankArray = [[NSMutableArray alloc]init];
    }
    return _bankArray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
